{extend name="$adminPage"}

{block name="content"}
<button class="layui-btn layui-btn-sm layui-btn-primary layui-border-green" onclick="yunj.openPopup('{:build_url(\'yunjDemoTableBuilderPkCodeView\')}')">代码查看</button>
<br>
<table type="yunj" id="demo"></table>
{/block}

{block name="script"}
<script type="text/javascript">
    layui.use(['jquery','table'],function (){
        let win = window;
        let doc = document;
        let $ = layui.jquery;
        let table = layui.table;

        // 前端获取选定数据的主键
        $(doc).bind(`yunj_table_demo_front_get_pk`, function (e,args){
            let codes = [];
            if(args.hasOwnProperty('data')){
                // 表头操作栏
                codes = [args.data.code];
            }else{
                // 表格操作栏
                codes = table.checkStatus(args.config.id).data.map(row => {
                    // row 数据行数据对象
                    return row.code;    // 当前数据行主键表头为code
                });
            }
            console.log('codes',codes);
            if(codes.length>0){
                yunj.alert(JSON.stringify({"codes":codes}));
            }else{
                yunj.error('请勾选数据行');
            }
        });
    });
</script>
{/block}